package mobi.greenplate.client.connect;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.message.BasicHeader;

/**
 *
 * @author dmakariev
 */
class PutTemplate extends DefaultTemplate {

    public PutTemplate(HttpClientTemplateContext context) {
        super(context);
    }   

    public int execute(HttpClient httpClient) throws Exception {
        final HttpPut httpPut = new HttpPut(getContext().getUrl());
        httpPut.setParams(getContext().getParams());
        httpPut.addHeader(new BasicHeader("Content-type", "application/xml"));
        httpPut.setHeader(new BasicHeader("Accept", "application/xml"));
        httpPut.setEntity(getContext().getHttpEntity());

        final HttpResponse response = httpClient.execute(httpPut);

        return handleResponse(response, getContext().getResponseHandler());
    }
}
